

#include "ly/properties.hpp"

#include <limits>
#include <stdexcept>

namespace ly {

// Properties 实现
Properties::Properties(/* args */) {
  // TODO: 实现构造函数
}

Properties::~Properties() {
  // TODO: 实现析构函数
}

property_names_id_type Properties::prop_name_id(const Variant& name) {
  auto pi = m_propname_ids_by_name.find(name);
  if (pi == m_propname_ids_by_name.end()) {
    auto id = m_propnames_by_id.size();
    m_propnames_by_id.insert(std::make_pair(id, name));
    m_propname_ids_by_name.insert(std::make_pair(name, id));
    return id;
  } else {
    return pi->second;
  }
}

properties_id_type Properties::properties_id(const properties_set& props) {
  auto pi = m_properties_ids_by_set.find(props);
  if (pi == m_properties_ids_by_set.end()) {
    auto id = m_properties_ids_by_set.size();
    m_properties_ids_by_set.insert(std::make_pair(props, id));
    m_properties_by_id.insert(std::make_pair(id, props));
    // for (properties_set::const_iterator nv = props.begin(); nv != props.end(); ++nv) {
    //   m_properties_component_table.insert(std::make_pair(*nv, properties_id_vector())).first->second.push_back(id);
    // }

    //  signal the change of the properties ID's. This way for example, the layer views
    //  can recompute the property selectors
    // if (mp_state_model) {
    //   mp_state_model->prop_ids_changed();
    // }

    return id;

  } else {
    return pi->second;
  }
}

}  // namespace ly
